// pages/ganZhi/ganZhi.js
const log = require('../log/log.js')
const util = require('../utils/util.js')
const sizhu = require('../sizhu/sizhu.js')
const app = getApp();

//十个天干         0     1     2     3    4     5     6     7    8     9
const ganList = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
//十二个地支       0     1     2     3    4     5     6     7     8     9    10   11
const zhiList = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
//60甲子
let jiaZiList = []
//节令
const jieLingList = ['立春', '惊蛰', '清明', '立夏', '芒种', '小暑', '立秋', '白露', '寒露', '立冬', '大雪', '小寒']
Page({
    /**
     * 页面的初始数据
     */
    data: {
        ganList1: ganList,
        ganList2: ganList,
        zhiList2: zhiList,
        ganList3: ganList,
        ganList4: ganList,
        zhiList4: zhiList,
        isScr: false,
        scrHeight: 400,
    },
    onShareAppMessage: function () {
        return {
            title: '分享六爻策给你的伙伴吧',
            path: '/pages/index/index',
            imageUrl: '/images/6YCSHARE.png'
        }
    },
    autoStyle: function () {
        var systeminfo = wx.getSystemInfoSync();
        log.info('index-autoStyle-获取系统参数', systeminfo)
        console.log(systeminfo);

        //px为单位
        var sW = systeminfo.screenWidth;
        var sH = systeminfo.screenHeight

        var rate = 750 / sW;

        //rpx为单位
        var rW = parseInt(sW * rate)
        var rH = parseInt(sH * rate)

        //屏幕长宽比
        var hwNum = sH / sW

        //pad的参数
        var pam = 1
        if (hwNum < 1.4) {
            pam = 0.72
        }

        var scrHeight = parseInt(rH * 0.5)

        var gzH = parseInt(sH * 0.05)
        var gzW = parseInt(sW * 0.11)
        var ganZhiLH = parseInt(sH * 0.048)
        var ganZhiW = parseInt(sW * 0.11)
        var ganZhiS = parseInt(sH * 0.035)

        var tmH = parseInt(sH * 0.05)
        var tmpH = tmH
        var tmpW = parseInt(sW * 0.22)
        var tmLH = parseInt(sH * 0.048)
        var tmW = parseInt(sW * 0.22)
        var tmS = parseInt(sH * 0.035)

        //设置按钮的高度和大小
        var bH = parseInt(rH * 0.05 * pam)
        var bW = parseInt(rW * 0.42)
        var bSize = parseInt(rH * 0.025 * pam)

        this.setData({
            scrHeight: scrHeight,
            gzH: gzH,
            gzW: gzW,
            ganZhiLH: ganZhiLH,
            ganZhiW: ganZhiW,
            ganZhiS: ganZhiS,
            tmH: tmH,
            tmpH: tmpH,
            tmpW: tmpW,
            tmLH: tmLH,
            tmW: tmW,
            tmS: tmS,
            bH: bH,
            bW: bW,
            bSize: bSize,
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        //自动样式
        this.autoStyle()

        //获取全局变量
        var longitude = app.globalData.longitude
        this.longitude = longitude

        log.info('ganZhi-onLoad-longitude-这里是打印全局变量', longitude)
        log.addFilterMsg('ganZhiOnloadLongitude')

        var nowDate = new Date()
        //初始化
        this.getJiaZi()

        //初始化
        this.showSiZhu(nowDate, longitude)

        //初始化
        this.showTime(nowDate)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },
    getJiaZi: function () {
        var m = 0, n = 0
        for (var i = 0; i < 60; i++) {
            jiaZiList[i] = m + "," + n
            m++
            n++
            m = m > 9 ? 0 : m
            n = n > 11 ? 0 : n
        }
    },
    showSiZhu: function (nowDate, longitude) {

        //获取当前四柱
        var ob = sizhu.getSiZhu(nowDate, longitude)

        log.info('ganZhi-showSiZhu-ob-这里是打印四柱返回值', ob)

        //月建的index
        var ganZhiList = []
        ganZhiList[0] = ganList.indexOf(ob.bz_jn.substr(0, 1))
        ganZhiList[1] = zhiList.indexOf(ob.bz_jn.substr(1, 1))
        ganZhiList[2] = ganList.indexOf(ob.bz_jy.substr(0, 1))
        ganZhiList[3] = zhiList.indexOf(ob.bz_jy.substr(1, 1))
        ganZhiList[4] = ganList.indexOf(ob.bz_jr.substr(0, 1))
        ganZhiList[5] = zhiList.indexOf(ob.bz_jr.substr(1, 1))
        ganZhiList[6] = ganList.indexOf(ob.bz_js.substr(0, 1))
        ganZhiList[7] = zhiList.indexOf(ob.bz_js.substr(1, 1))

        //初始化四柱
        this.initSiZhuColumn(ganZhiList)

        //获取当前的六月一日是什么年
        var curYear = nowDate.getFullYear()
        //获取当前的六月一日是什么年
        nowDate = new Date((curYear.toString() + "-06-01 00:00:00").replace(/-/g, '/'))
        //获取六一的四柱
        var curOb = sizhu.getSiZhu(nowDate, longitude)

        console.log(curOb);
        //当前年
        this.curYear = curYear
        //当前年的天干数字
        this.yearGanNum = ganList.indexOf(curOb.bz_jn.substr(0, 1))
        //当前年的地支数字
        this.yearZhiNum = zhiList.indexOf(curOb.bz_jn.substr(1, 1))
        //当前年的六十甲子数字
        this.yearNum = jiaZiList.indexOf(this.yearGanNum + "," + this.yearZhiNum)
    },
    showTime: function (nowDate) {
        //当前时间 年月日 时分秒
        var curYear = nowDate.getFullYear()
        var curMonth = nowDate.getMonth() + 1
        var curDay = nowDate.getDate()
        var curHour = nowDate.getHours()

        log.info('ganZhi-showTime-nowDate-这里是打印当前时间', nowDate)

        //选中年
        this.chooseYear = curYear
        //选中月
        this.chooseMonth = curMonth

        //初始化时间选择轴
        this.initColumn(curMonth)


        var timeList = [curYear, curMonth - 1, curDay - 1, curHour]

        log.info('ganZhi-showTime-timeList-这里是打印当前时间列表', timeList)

        this.setData({
            timeList: timeList
        })
    },
    //初始化时间选择轴
    initColumn(curMonth) {
        let years = []
        let months = []
        let days = []
        let hours = []

        //初始化只加载50年之内的，后续动一下加载一下
        for (let i = 0; i <= 2100; i++) {
            years.push((i + "").padStart(4, 0))
        }
        for (let i = 1; i <= 12; i++) {
            if (i < 10) {
                i = "0" + i;
            }
            months.push(i + '')
        }

        if (curMonth == 1 || curMonth == 3 || curMonth == 5 || curMonth == 7 || curMonth == 8 || curMonth == 10 || curMonth == 12) {
            for (let i = 1; i <= 31; i++) {
                if (i < 10) {
                    i = "0" + i;
                }
                days.push(i + '')
            }
        }
        if (curMonth == 4 || curMonth == 6 || curMonth == 9 || curMonth == 11) {
            for (let i = 1; i <= 30; i++) {
                if (i < 10) {
                    i = "0" + i;
                }
                days.push(i + '')
            }
        }
        if (curMonth == 2) {
            days = this.setFebDays()
        }
        for (let i = 0; i <= 23; i++) {
            if (i < 10) {
                i = "0" + i;
            }
            hours.push(i + '')
        }
        this.setData({
            years,
            months,
            days,
            hours
        })
    },
    //计算二月份天数
    setFebDays() {
        let year = parseInt(this.chooseYear);
        let temp = [];
        if (year % (year % 100 ? 4 : 400) ? false : true) {
            for (let i = 1; i <= 29; i++) {
                if (i < 10) {
                    i = "0" + i;
                }
                temp.push("" + i);
            }
            this.setData({
                days: temp
            });
        } else {
            for (let i = 1; i <= 28; i++) {
                if (i < 10) {
                    i = "0" + i;
                }
                temp.push("" + i);
            }
            this.setData({
                days: temp
            });
        }
        return temp;
    },
    showTimeByParam: function (date) {
        //当前时间 年月日 时分秒
        var curYear = date.getFullYear()
        var curMonth = date.getMonth() + 1
        var curDay = date.getDate()
        var curHour = date.getHours()

        var timeList = [curYear, curMonth - 1, curDay - 1, curHour]

        this.setData({
            timeList: timeList
        })
    },
    timeChange: function (e) {
        var timeList = e.detail.value

        let chooseYear = timeList[0];
        let chooseMonth = timeList[1];

        //获取年份 用于计算改年的2月份为平年还是闰年
        if (chooseYear != this.chooseYear) {
            this.chooseYear = chooseYear
            if (this.chooseMonth == 1) {
                this.setFebDays()
            }
        }

        if (chooseMonth != this.chooseMonth) {
            this.chooseMonth = chooseMonth
            //当前第二为月份时需要初始化当月的天数
            let num = timeList[1] + 1;
            let temp = [];
            if (num == 1 || num == 3 || num == 5 || num == 7 || num == 8 || num == 10 || num == 12) { //31天的月份
                for (let i = 1; i <= 31; i++) {
                    if (i < 10) {
                        i = "0" + i;
                    }
                    temp.push("" + i);
                }
                this.setData({
                    days: temp
                });
            } else if (num == 4 || num == 6 || num == 9 || num == 11) { //30天的月份
                for (let i = 1; i <= 30; i++) {
                    if (i < 10) {
                        i = "0" + i;
                    }
                    temp.push("" + i);
                }
                this.setData({
                    days: temp
                });
            } else if (num == 2) { //2月份天数
                this.setFebDays()
            }
        }

        var date = new Date((timeList[0].toString() + "-" + (timeList[1] + 1).toString() + "-" + (timeList[2] + 1).toString() + " " + timeList[3].toString() + ":00:00").replace(/-/g, '/'))

        this.showSiZhu(date, this.longitude)
    },
    //初始化时间选择轴
    initSiZhuColumn(ganZhiList) {
        //获取新的地支列表
        var zhiList1 = this.siZhuPush(ganZhiList[0])
        var zhiList3 = this.siZhuPush(ganZhiList[4])

        this.setData({
            zhiList1: zhiList1,
            zhiList3: zhiList3,
        })

        //重新给地支赋值
        ganZhiList[1] = zhiList1.indexOf(zhiList[ganZhiList[1]])
        ganZhiList[5] = zhiList3.indexOf(zhiList[ganZhiList[5]])

        //将地支列表进行存储
        this.zhiList1 = zhiList1
        this.zhiList3 = zhiList3

        //重新赋值
        this.ganZhiList = ganZhiList
        this.setData({
            ganZhiList: ganZhiList
        })
    },
    monthGanStart: function (yearGan) {
        //月的起始天干
        var monthStartGan = 0
        // 甲己之年丙做首；乙庚之年卯为头；
        // 丙辛必定寻庚起；丁壬壬位顺流行；
        // 还有戊癸何方觅，甲定之上好追求。
        if (yearGan == 0 || yearGan == 5) {
            monthStartGan = 2
        } else if (yearGan == 1 || yearGan == 6) {
            monthStartGan = 4
        } else if (yearGan == 2 || yearGan == 7) {
            monthStartGan = 6
        } else if (yearGan == 3 || yearGan == 8) {
            monthStartGan = 8
        } else if (yearGan == 4 || yearGan == 9) {
            monthStartGan = 0
        }
        return monthStartGan
    },
    hourGanStart: function (dayGan) {
        //时的起始天干
        var hourStartGan = 0
        // 甲己还生甲，乙庚丙作初,
        // 丙辛从戊起，丁壬庚子居，
        // 戊癸何方发，壬子是真途。
        if (dayGan == 0 || dayGan == 5) {
            hourStartGan = 0
        } else if (dayGan == 1 || dayGan == 6) {
            hourStartGan = 2
        } else if (dayGan == 2 || dayGan == 7) {
            hourStartGan = 4
        } else if (dayGan == 3 || dayGan == 8) {
            hourStartGan = 6
        } else if (dayGan == 4 || dayGan == 9) {
            hourStartGan = 8
        }
        return hourStartGan
    },
    //初始化时间选择轴
    initZhiColumn(ganZhiList) {

        //判断是什么在变动
        var changeNum = this.whatChange(ganZhiList)

        //如果年的天干动了，则月的天干也得变
        if (changeNum == 0) {
            //年的天干
            var yearGan = ganZhiList[0]
            var oldYearGan = this.data.ganZhiList[0]
            if ((yearGan + oldYearGan) % 2 == 1) {
                //获取新的地支列表
                var zhiList1 = this.siZhuPush(ganZhiList[0])

                /*************赋值区域*************** */
                this.zhiList1 = zhiList1

                this.setData({
                    zhiList1: zhiList1,
                })
            }
            //然后将年地支赋值为0
            ganZhiList[1] = 0

            //月的地支
            var monthZhi = ganZhiList[3]
            //月的起始天干
            var monthStartGan = this.monthGanStart(yearGan)
            //获取真正的月的天干
            var monthGan = monthZhi < 2 ? monthStartGan + monthZhi : (monthZhi - 2 + monthStartGan) % 10
            //将月份的天干进行赋值
            ganZhiList[2] = monthGan
        }
        //月份的天干变动，则月份地支也得变动
        else if (changeNum == 2) {
            //年的天干
            var yearGan = ganZhiList[0]
            //月的起始天干
            var monthStartGan = this.monthGanStart(yearGan)
            //月的天干
            var monthGan = ganZhiList[2]
            //获取新的地支
            var monthZhi = monthGan < monthStartGan ? monthGan + 10 - monthStartGan + 2 : monthGan - monthStartGan + 2
            //然后将月地支赋值为0
            ganZhiList[3] = monthZhi
        }
        //如果是月的地支变动，则月的天干也得变动
        else if (changeNum == 3) {
            //年的天干
            var yearGan = ganZhiList[0]
            //月的起始天干
            var monthStartGan = this.monthGanStart(yearGan)
            //获取当前地支
            var monthZhi = ganZhiList[3]
            //月的天干地支有些区别
            var monthGan = monthZhi < 2 ? monthStartGan + monthZhi : (monthZhi - 2 + monthStartGan) % 10
            //将月份的天干进行赋值
            ganZhiList[2] = monthGan
        }
        //如果是日的天干变动，则时的天干也得变动
        else if (changeNum == 4) {
            //日的天干
            var dayGan = ganZhiList[4]

            var oldDayGan = this.data.ganZhiList[4]
            if ((dayGan + oldDayGan) % 2 == 1) {
                //获取新的地支列表
                var zhiList3 = this.siZhuPush(ganZhiList[4])

                /*************赋值区域*************** */
                this.zhiList3 = zhiList3

                this.setData({
                    zhiList3: zhiList3,
                })
            }
            //然后将日的地支赋值为0
            ganZhiList[5] = 0

            //时的地支
            var hourZhi = ganZhiList[7]
            //时的起始天干
            var hourStartGan = this.hourGanStart(dayGan)
            //获取真正的月的天干
            var hourGan = (hourStartGan + hourZhi) % 10
            //将时份的天干进行赋值
            ganZhiList[6] = hourGan
        }
        //如果是时的天干变动，则时的地支也得变动
        else if (changeNum == 6) {
            //日的天干
            var dayGan = ganZhiList[4]
            //时的起始天干
            var hourStartGan = this.hourGanStart(dayGan)
            //时的天干
            var hourGan = ganZhiList[6]
            //获取新的地支
            var hourZhi = hourGan < hourStartGan ? hourGan + 10 - hourStartGan : hourGan - hourStartGan
            //然后将月地支赋值为0
            ganZhiList[7] = hourZhi
        }
        //如果时的地支变动，则时的天干也得变动
        else if (changeNum == 7) {
            //日的天干
            var dayGan = ganZhiList[4]
            //月的起始天干
            var hourStartGan = this.hourGanStart(dayGan)
            //时的地支
            var hourZhi = ganZhiList[7]
            //获取真正的月的天干
            var hourGan = (hourStartGan + hourZhi) % 10
            //将时份的天干进行赋值
            ganZhiList[6] = hourGan
        }

        /*************赋值区域*************** */
        this.ganZhiList = ganZhiList

        this.setData({
            ganZhiList: ganZhiList
        })
        /*************赋值区域*************** */
    },
    siZhuPush: function (gan) {
        //不同开头的天干的地支列表是固定的
        var zhiListArr = []
        var startZhi = gan % 2
        for (var i = 0; i < 6; i++) {
            zhiListArr.push(zhiList[startZhi])
            startZhi = startZhi + 2
        }
        return zhiListArr
    },
    whatChange: function (ganZhiList) {
        var oldGanZhiList = this.ganZhiList
        for (var i = 0; i < 8; i++) {
            if (oldGanZhiList[i] != ganZhiList[i]) {
                return i
            }
        }
    },
    ganZhiChange: function (e) {
        var dateList = []
        var longitude = this.longitude
        var ganZhiList = e.detail.value

        //初始化干支数据
        this.initZhiColumn(ganZhiList)

        //年的处理
        var offset = jiaZiList.indexOf(ganZhiList[0] + "," + zhiList.indexOf(this.zhiList1[ganZhiList[1]])) - this.yearNum

        //将当前年取余，获取相同的最小年
        var startYear = this.curYear % 60
        //开始年是通过浑天甲子之差，再由起始年加减得到的
        startYear = (startYear + offset + 60) % 60

        //120年后才是准的
        startYear += 120

        //月的处理
        //正月是寅，所以减2
        var monthZhi = ganZhiList[3]
        var monthOffset = monthZhi > 1 ? monthZhi - 2 : monthZhi + 10

        //时的处理
        var hourZhi = ganZhiList[7]
        hourZhi = hourZhi * 2

        for (var n = startYear; n < 2100; n += 60) {

            //获取当前年和后一年的12节令
            var jieLingArr = sizhu.nianLiHTML(n)
            var jieLingArr2 = sizhu.nianLiHTML(n + 1)
            var jieLingAllList = []

            var isStart = false
            var isEnd = true
            //存放数值
            for (var i = 0; i < jieLingArr.length; i++) {
                if (isStart || jieLingArr[i].jieQi == jieLingList[0]) {
                    jieLingAllList.push(jieLingArr[i])
                    isStart = true
                }
            }
            for (var i = 0; i < jieLingArr2.length; i++) {
                if (isEnd) {
                    jieLingAllList.push(jieLingArr2[i])
                    if (jieLingArr2[i].jieQi == jieLingList[0]) {
                        isEnd = false
                        break
                    }
                }
            }

            //获取头和尾,需要注意边界
            var startTime = null, endTime = null
            for (var i = 0; i < jieLingAllList.length; i++) {
                if (jieLingAllList[i].jieQi == jieLingList[monthOffset]) {
                    startTime = jieLingAllList[i].date
                    endTime = jieLingAllList[i + 1].date
                    break
                }
            }

            //比对当前日、当前小时的甲子日是否在其中
            //获取开始时间的天干地支
            var ob = sizhu.getSiZhu(startTime, longitude)
            var dayGan1 = ganList.indexOf(ob.bz_jr.substr(0, 1))
            var dayZhi1 = zhiList.indexOf(ob.bz_jr.substr(1, 1))

            //获取结束时间的天干地支
            ob = sizhu.getSiZhu(endTime, longitude)
            var dayGan2 = ganList.indexOf(ob.bz_jr.substr(0, 1))
            var dayZhi2 = zhiList.indexOf(ob.bz_jr.substr(1, 1))

            var jiaZiNum1 = jiaZiList.indexOf(dayGan1 + "," + dayZhi1)
            var jiaZiNum2 = jiaZiList.indexOf(dayGan2 + "," + dayZhi2)
            var jiaZiDayNum = jiaZiList.indexOf(ganZhiList[4] + "," + zhiList.indexOf(this.zhiList3[ganZhiList[5]]))

            var date = null

            if (jiaZiNum1 < jiaZiNum2 && (jiaZiDayNum >= jiaZiNum1 && jiaZiDayNum <= jiaZiNum2)) {
                //获取甲子天数差
                var offset = jiaZiDayNum - jiaZiNum1
                date = new Date(startTime)
                date.setDate(startTime.getDate() + offset);
                date.setHours(hourZhi)

            } else if (jiaZiNum1 > jiaZiNum2 && ((jiaZiDayNum >= jiaZiNum1 && jiaZiDayNum <= 59) || (jiaZiDayNum <= jiaZiNum2))) {
                if (jiaZiDayNum >= jiaZiNum1) {
                    //获取甲子天数差
                    var offset = jiaZiDayNum - jiaZiNum1
                    date = new Date(startTime)
                    date.setDate(startTime.getDate() + offset);
                    date.setHours(hourZhi)

                } else if (jiaZiDayNum <= jiaZiNum2) {
                    //获取甲子天数差
                    var offset = jiaZiNum2 - jiaZiDayNum
                    date = new Date(endTime)
                    date.setDate(endTime.getDate() - offset);
                    date.setHours(hourZhi)
                }

            } else {
                continue
            }
            if (date >= startTime && date <= endTime) {
                //给时间赋值
                date.setMinutes(0)
                date.setSeconds(0)

                var ob = sizhu.getSiZhu(date, longitude)
                var obGan = ganList.indexOf(ob.bz_jr.substr(0, 1))
                var obZhi = zhiList.indexOf(ob.bz_jr.substr(1, 1))
                var obNum = jiaZiList.indexOf(obGan + "," + obZhi)
                if ((obNum > jiaZiDayNum && Math.abs(obNum - jiaZiDayNum) == 1) || (obNum < jiaZiDayNum && Math.abs(obNum - jiaZiDayNum) == 59)) {
                    console.log("当前年大一天");
                    date.setDate(date.getDate() - 1)
                } else if ((obNum < jiaZiDayNum && Math.abs(obNum - jiaZiDayNum) == 1) || (obNum > jiaZiDayNum && Math.abs(obNum - jiaZiDayNum) == 59)) {
                    console.log("当前年小一天");
                    date.setDate(date.getDate() + 1)
                }

                var dateObj = new Object()
                var realYear = date.getFullYear()

                dateObj.dateStr = util.formatTime(date).padStart(19, 0)
                dateObj.date = date
                dateObj.year = (realYear + "").padStart(4, 0)
                dateObj.nianHao = sizhu.nianHao(realYear)
                dateList.push(dateObj)
            }
        }
        if (dateList.length > 15) {
            this.setData({
                isScr: true
            })
        }
        // if (dateList.length > 0) {
        //     var len = dateList.length
        //     this.showTimeByParam(dateList[len - 1].date)
        // }

        console.log(dateList);
        this.setData({
            dateList: dateList
        })

    },
    nianHao: function (e) {
        var nianHao = e.currentTarget.dataset.id
        wx.showToast({
            title: nianHao,
            icon: 'none',
            duration: 3500
        })
    },
    reset: function () {
        var nowDate = new Date()
        //初始化
        this.showSiZhu(nowDate, this.longitude)

        //初始化
        this.showTime(nowDate)

        //清空输入框的值
        this.setData({
            year: '',
            month: '',
            day: '',
            hour: '',
            dateList: null
        })
    },
    yearValue: function (e) {
        this.setData({
            year: e.detail.value
        })
    },
    monthValue: function (e) {
        this.setData({
            month: e.detail.value
        })
    },
    dayValue: function (e) {
        this.setData({
            day: e.detail.value
        })
    },
    hourValue: function (e) {
        this.setData({
            hour: e.detail.value
        })
    },
    submit: function () {
        var reg = /^-?\d+$/;

        console.log(this.data);

        var year = this.data.year
        var month = this.data.month
        var day = this.data.day
        var hour = this.data.hour

        if (year != "" && !reg.test(year)) {
            wx.showToast({
                title: '请输入年份',
                icon: 'none',
                duration: 1500
            })
            return;
        } else if (year < -3000 || year > 3000) {
            wx.showToast({
                title: '年份范围-3000 - 3000',
                icon: 'none',
                duration: 1500
            })
            return;
        } else if (month != "" && !reg.test(month)) {
            wx.showToast({
                title: '请输入月份',
                icon: 'none',
                duration: 1500
            })
            return;
        } else if (month < 1 || month > 12) {
            wx.showToast({
                title: '月份范围1 - 12',
                icon: 'none',
                duration: 1500
            })
            return;
        } else if (day != "" && !reg.test(day)) {
            wx.showToast({
                title: '请输入日期',
                icon: 'none',
                duration: 1500
            })
            return;
        } else if (day < 1 || day > 31) {
            wx.showToast({
                title: '日期范围1 - 31',
                icon: 'none',
                duration: 1500
            })
            return;
        } else if (hour != "" && !reg.test(hour)) {
            wx.showToast({
                title: '请输入小时',
                icon: 'none',
                duration: 1500
            })
            return;
        } else if (hour < 0 || hour > 23) {
            wx.showToast({
                title: '小时范围0 - 23',
                icon: 'none',
                duration: 1500
            })
            return;
        }

        if (year && month && day && hour) {
            var nowDate = new Date()
            nowDate.setFullYear(parseInt(year))
            nowDate.setMonth(parseInt(month) - 1)
            nowDate.setDate(parseInt(day))
            nowDate.setHours(parseInt(hour))

            console.log(nowDate);

            //获取年号
            var nianHao = sizhu.nianHao(parseInt(year))

            if (nianHao) {
                wx.showToast({
                    title: nianHao,
                    icon: 'none',
                    duration: 1500
                })
            }

            //初始化
            this.showSiZhu(nowDate, this.longitude)

            //初始化
            // this.showTime(nowDate)

        } else {
            wx.showToast({
                title: '年月日时均不可为空',
                icon: 'none',
                duration: 1500
            })
            return;
        }
    },
    adLoad() {
        log.info('小程序视频广告加载成功')
        log.addFilterMsg('adLoad-GZ')
    },
    adError(err) {
        log.info('小程序视频广告加载失败', err)
        log.addFilterMsg('adError-GZ')
    },
    adClose(){
        log.info('小程序视频广告关闭')
        log.addFilterMsg('adClose-GZ')
    }
})